package com.bzy.bookservice.service;

import com.bzy.Book;
import com.bzy.BookInfo;
import com.bzy.DataPage;
import com.bzy.bookservice.mapper.BookInfoMapper;
import com.bzy.bookservice.mapper.BookMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @ Author     : Bzy.
 * @ Date       : 2020/12/28 -- 19:49
 * @ Version:     $ 1.0
 */
@Service
public class BookServiceImpl implements BookService {

    @Autowired
    private BookMapper bookMapper;

    @Autowired
    private BookInfoMapper bookInfoMapper;

    @Override
    public DataPage<Book> getAllBook(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);//1 3
        List<Book> bookList = bookMapper.selectAllBook();
        PageInfo<Book> info = new PageInfo<>(bookList);
        DataPage<Book> bookPage = new DataPage<>();
        bookPage.setPageCount(info.getPages());
        bookPage.setRowCount((int) info.getTotal());
        bookPage.setPageNum(pageNum);
        bookPage.setPageSize(pageSize);
        bookPage.setDataList(bookList);
        return bookPage;
    }

    @Override
    public List<BookInfo> getAllBookInfo() {
        return bookInfoMapper.selectAllBookInfo();
    }
}
